<template>
  <a-spin :spinning="confirmLoading">
    <j-vxe-table
      keep-source
      :ref="refKeys[0]"
      bordered
      :dataSource="dataSource"
      :columns="packageColumns"
      :disabled="true"
      class="bold-border"
    >
      <template v-slot:isBrought="{ row }">
        <j-dict-select-tag :disabled="true" v-model="row.isBrought" dictCode="yn"/>
      </template>

      <template v-slot:packageInOutType="{ row }">
        <j-dict-select-tag :disabled="true" v-model="row.packageInOutType" dictCode="package_type"/>
      </template>
      <template v-slot:proportion="{ row }">

        <a-input-number :disabled="true" style="width:100%" v-model="row.proportion" :default-value="0" />
      </template>

      <template v-slot:action="{ row }">
        <a v-if="row.patternFile" @click="handlePreviewFile(row)">查看版样</a>
      </template>
    </j-vxe-table>
  </a-spin>
</template>

<script>
import { httpAction, getAction, putAction, getFileAccessHttpUrl } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import $file from '@/libs/globalFunction/file'
import { FilePreview } from '@/utils/tslCommon'

export default {
  name: 'ErpPackageDetailForm',
  components: {},
  props: {},
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      refKeys:['package'],
      confirmLoading: false,
      validatorRules: {},
      url: {
        detailList: '/packageprocessconfirmation/erpPackageProcessConfirmation/queryPackageDetailById',
      },
      loading: false,
      dataSource: [],
      ipagination: {
        current: 1,
        pageSize: 30,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      packageColumns: [
        {
          title: '物料编号',
          dataIndex: 'packageCode',
          key: 'packageCode',
        },
        {
          title: '物料名称',
          dataIndex: 'packageName',
          key: 'packageName',
        },
        {
          title: '规格型号',
          dataIndex: 'noneSpec',
          key: 'noneSpec',
        },
        {
          title: '是否自带',
          dataIndex: 'isBrought',
          key: 'isBrought',
          type: JVXETypes.slot,
          slotName:'isBrought',
        },
        {
          title: '包材类别',
          dataIndex: 'packageInOutType',
          key: 'packageInOutType',
          type: JVXETypes.slot,
          slotName:'packageInOutType',
        },
        {
          title: '比例数量',
          dataIndex: 'proportion',
          type: JVXETypes.slot,
          slotName:'proportion',
          key: 'proportion',
        },
        {
          title: '损耗率(%)',
          dataIndex: 'lossRate',
          key: 'lossRate',
          type: JVXETypes.input,
        },
        {
          title: '材质',
          dataIndex: 'materialQuality',
          key: 'materialQuality',
        },
        {
          title: '尺寸',
          dataIndex: 'size',
          key: 'size',
        },
        {
          title: '包装要求',
          dataIndex: 'requirements',
          key: 'requirements',
          type: JVXETypes.input,
        },
        {
          title: '版样',
          dataIndex: 'patternFile',
          key: 'patternFile',
          type: JVXETypes.file,
          minWidth: '120px',
          token: true,
        },
        {
          title: '操作',
          key: 'action',
          type: JVXETypes.slot,
          fixed: 'right',
          minWidth: '100px',
          align: 'center',
          slotName: 'action',
        },
      ],
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    detail(record) {
      getAction(this.url.detailList, { orderCode: record.orderCode, orderProductId: record.orderProductId })
        .then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result || []
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleFileChange(fileList) {
      if (!fileList || fileList.length <= 0) {
        return
      }
      fileList.forEach((item) => {
        item.fileSizeFormat = $file.calculateFileSize(item.fileSize)
      })
      this.fileTable.dataSource = fileList
    },
    handlePreviewFile(row) {
      FilePreview(row.patternFile)
    },
    handleDownloadFile() {},
    // 附件下载
    getFileUrl(file) {
      return getFileAccessHttpUrl(file.row.patternFile)
    },
  },
}
</script>
<style scoped></style>
